#include <iostream>

int main() {
    // 基本指针操作
    int num = 42;
    int* ptr = &num;

    std::cout << "Value of num: " << num << std::endl;
    std::cout << "Address of num: " << ptr << std::endl;
    std::cout << "Accessing num through pointer: " << *ptr << std::endl;

    // 指针数组
    int arr[] = {1, 2, 3, 4, 5};
    int* arrPtr = arr;

    std::cout << "\nTraversing array using pointer: ";
    for (int i = 0; i < 5; i++) {
        std::cout << *(arrPtr + i) << " ";
    }

    // 动态内存分配
    int* dynamicArr = new int[3];
    dynamicArr[0] = 10;
    dynamicArr[1] = 20;
    dynamicArr[2] = 30;

    std::cout << "\n\nDynamic array contents: ";
    for (int i = 0; i < 3; i++) {
        std::cout << dynamicArr[i] << " ";
    }

    // 释放动态内存
    delete[] dynamicArr;

    return 0;
}